const express = require('express');
const morgan = require('morgan');
const router = require('./router/index')
const dotenv = require("dotenv")
const errorHandler = require('./middleware/error-handle');
const app = express();
dotenv.config()

require('./model')

console.log(errorHandler);

//跨域请求
const cors = require('cors');

app.use(cors());
app.use(morgan('dev'));

// app.use(express.urlencoded());
app.use(express.json());

const PORT = process.env.PORT || 3000;

// 挂载路由
app.use('/api', router)

// 挂在统一处理服务端错误中间件
app.use(errorHandler())

app.listen(PORT, () => {
  console.log('Serve is run at http://localhost:' + PORT);
})